   package com.javalong.affairs.module.notifything.fragment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

import com.javalong.affairs.R;
import com.javalong.affairs.base.fragment.BaseFragment;
import com.javalong.affairs.module.notifything.activity.MsgDetailActivity;
import com.javalong.affairs.module.notifything.activity.NotificationActivity;
import com.javalong.affairs.module.notifything.adapter.NotificationAdapter;
import com.javalong.affairs.module.notifything.adapter.NotificationAdapter.Type;
import com.javalong.affairs.base.constant.BundleKey;
import com.javalong.affairs.base.constant.DataType;
import com.javalong.affairs.base.constant.MapKey;
import com.javalong.affairs.base.data.AllData;
import com.javalong.affairs.base.manager.IntentManager;
import com.javalong.affairs.base.model.SimpleMessage;
import com.javalong.affairs.base.ui.SimplePullRefreshList;

   public class NotificationReceiveFragment extends BaseFragment implements
		OnItemClickListener {
	private SimplePullRefreshList lv_receiver;
	private NotificationAdapter ad_notification;
	private List<SimpleMessage> msgList;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_notificationreceive,
				container, false);
		lv_receiver = (SimplePullRefreshList) view
				.findViewById(R.id.lv_receiver);
		msgList = AllData.GetInstance().appendListData(
				R.string.data_notification_receive,
				new ArrayList<SimpleMessage>());
		ad_notification = new NotificationAdapter(getActivity(), msgList,
				Type.Receive);
		lv_receiver.setAdapter(ad_notification);
		lv_receiver.initData(getMapData());
		lv_receiver.refresh();
		lv_receiver.setOnItemClickListener(this);
		((NotificationActivity) getActivity()).topTitle.setTitle("接收列表");
		return view;
	}

	private Map<String, Object> getMapData() {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put(MapKey.ACTION_NAME, "SendMessage");
		param.put(MapKey.METHOD_NAME, "outReceive_message");
		param.put(MapKey.DATA_RESID, R.string.data_notification_receive);
		param.put(MapKey.DATA_TYPE, DataType.LIST_SIMPLEMESSAGE);
		return param;
	}

	@Override
	public void refresh() {
		super.refresh();
		lv_receiver.refresh();
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		if (position < 2) {
			return;
		}
		if (msgList != null && msgList.size() > position - 2) {
			SimpleMessage msgInfo = msgList.get(position - 2);
			Bundle bundle = new Bundle();
			bundle.putString(BundleKey.MSGID, msgInfo.messageId);
			bundle.putString(BundleKey.SIMPLEMSGID, msgInfo.id);
			bundle.putBoolean(BundleKey.NODELETE, msgInfo.del == 0);
			IntentManager.doActivity(getActivity(), MsgDetailActivity.class,
					bundle);
		}
	}

}
